package fudan.se.project.repository.projection.customized;

import fudan.se.project.domain.conference.production.Paper;
import fudan.se.project.domain.conference.production.ReviewInfo;
import fudan.se.project.repository.projection.summary.RoleSummary;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import static fudan.se.project.repository.projection.customized.UnconfirmedPaperProjection.Release.FIRST_RELEASE;

public class UnconfirmedPaperProjection {


    public enum Release {
        FIRST_RELEASE, // 0
        SECOND_RELEASE // 1
    }

    private final Release release;
    private final Paper paper;

    private UnconfirmedPaperProjection(Release release, Paper paper) {
        this.release = release;
        this.paper = paper;
    }

    public String getTitle() {
        return paper.getTitleText();
    }

    public List<RoleSummary> getPcMembers() {
        final int assignedCount = 3;
        int ver = (release == FIRST_RELEASE) ? 0 : 1;
        ArrayList<RoleSummary> list = new ArrayList<>(assignedCount);
        for (ReviewInfo reviewInfo : paper.getReviewInfos()) {
            if (reviewInfo.getVersion() == ver) {
                list.add(new RoleSummary(reviewInfo.getPcMember()));
            }
        }
        return list;
    }

    public static UnconfirmedPaperProjection project(Release release, Paper paper) {
        return new UnconfirmedPaperProjection(release, paper);
    }

    public static List<UnconfirmedPaperProjection> project(Release release, Collection<Paper> values) {
        ArrayList<UnconfirmedPaperProjection> arrayList = new ArrayList<>(values.size());
        for (Paper value : values) {
            arrayList.add(project(release, value));
        }
        return arrayList;
    }


}
